<?php
/**
 * Given folder name, creates and displays images inside that folder.
 * 
 * Enter folder name. Every image in that folder and into subfolders will be indexed and ready
 * to display on your website without any further need for maintenance.
 * 
 * @version 0.0.1
 * @author Bartosz Czaban 
 */
class FTPGallery
{

	// configuration variables
	private $allowed_extensions = array("jpg", "gif", "png");

	// reserved variables - do not modify
	private $root_dir;
	private $img_list;

	public function __construct($init_root_dir = '.')
	{
		if (is_dir($init_root_dir) && is_readable($init_root_dir))
		{
			$this->root_dir = $init_root_dir;
		} else {
			throw new Exception("Invalid directory name provided for the constructor!");
		}
		
	}

	public function getContent()
	{
		$images = $this->getImages();
		
		foreach ($images as $image)
		{
			echo $image;
		}
	}

	function getImages($filepath='')
	{
		$img_names = array();
		
		try
		{
			$current_path = dirname(_FILE_).DIRECTORY_SEPARATOR.$this->root_dir.DIRECTORY_SEPARATOR.$filepath;
			$files = new DirectoryIterator($current_path);
			
			foreach($files as $file)
			{
				if (!$file->isDot && !$file->isDir() && in_array($file->getExtension(), $this->allowed_extensions))
				{
					$img_names[] = $file;
				}
			}
		} catch (UnexpectedValueException $exception) {
							
			echo 'Error: '.$exception->getMessage();
		}
		
		return $img_names;
	}
}

?>